import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:robotcontrol/entity/common_item.dart';
import 'package:robotcontrol/utils/cache_image.dart';
import 'package:robotcontrol/utils/toast.dart';

class BannerWidget extends StatelessWidget {
  List list; //banner数据
  BannerWidget({Key key, this.list}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Swiper(
      autoplay: true,
      itemBuilder: (BuildContext context, int index) {
        return Stack(
          children: <Widget>[
            Container(
              // decoration:装饰,设置子控件的背景颜色、形状等
              decoration: BoxDecoration(
                  image: DecorationImage(
                      // image: cachedNetworkImageProvider(list[index].data.cover.feed)
                      image: cachedNetworkImageProvider(list[index].data.cover.feed),
                      fit: BoxFit.cover)),
            ),
            //banner 底部黑条
            Positioned(
                child: Container(
                  padding: EdgeInsets.fromLTRB(15, 10, 0, 10),
                  decoration: BoxDecoration(color: Colors.black12),
                  child: Text(
                    list[index].data.title,
                    style: TextStyle(color: Colors.white, fontSize: 12),
                  ),
                ),
                // 默认显示内容宽度
                width: MediaQuery.of(context).size.width - 30,
                bottom: 0)
          ],
        );
      },
      onTap: (index) {
        ToastUtil.toast("2222222222222");
      },
      itemCount: list?.length ?? 0,
      //指示器
      pagination: SwiperPagination(
          alignment: Alignment.bottomCenter,
          builder: DotSwiperPaginationBuilder(
              size: 8,
              activeSize: 8,
              activeColor: Colors.white,
              color: Colors.white24)),
    );
  }
}
